// pages/present/present.js
var app = getApp()
var util = require('../../utils/util.js')
var host = app.globalData.host
var self = null

function getAdv() {
  var url = host + '/xhc/adv/list'
  var width = wx.getSystemInfoSync().windowWidth
  var cardHeight = (width - 68) / 2 / 1.42 + 'px'
  app.request({
    url: url,
    data: {
      type: 2
    }, success: function (res) {
      self.setData({
        adv: res.data.info,
        cardHeight: cardHeight
      })
    }
  })
}

Page({

  /**
   * 页面的初始数据
   */
  data: {
    adv: [],
    list: [],
    cardHeight: '',
    themeColor: '',
    defaultColor: '',
    borderColor: ''
  },

  getStyle() {
    wx.setNavigationBarTitle({
      title: '小礼品'
    })
    self.setData({
      themeColor: app.globalData.themeColor,
      defaultColor: app.globalData.defaultColor,
      borderColor: app.globalData.borderColor
    })
  },
  getList() {
    app.request({
      url: host + '/xhc/present/list',
      data: {
      },
      success: function (res) {
        console.log(res.data.info)
        self.setData({
          list: res.data.info
        })
      }, fail: function (msg) {
        console.warn(msg)
      }
    })
  },
  plusZhenyi() {
    wx.navigateTo({
      url: '/pages/zhenyi/zhenyi',
    })
  },
  content(e) {
    wx.navigateTo({
      url: '/pages/content/content?images=' + e.currentTarget.dataset.images + '&title=' + e.currentTarget.dataset.title,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    self = this
    getAdv()
    self.getList()
    self.getStyle()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})